import socket

class Communication (object):
    
    def __init__ (self, host, port):
        self.host = host
        self.port = port
        print 'Connection to the server (%s, %d) ...' % (self.host, self.port)

        self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.conn.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.conn.connect((self.host, self.port))

    def receive (self):
        data = self.conn.recv(1024)
        while "end" not in data:    
            data += "" + self.conn.recv(1024)
        return data
    
    def send (self, data):
        self.chaineToSend=data
        print data
        self.conn.sendall(self.chaineToSend)
    
    def close(self):
        self.conn.close()
        
    
